deploy{
  final DeploymentUnit deploymentUnit=phaseContext.getDeploymentUnit();
  final DeploymentUnit parent=deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
  final ServiceTarget serviceTarget=phaseContext.getServiceTarget();
  final ResourceRoot deploymentRoot=deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
  if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
    if (deploymentUnit.getParent() == null && CdiAnnotationMarker.cdiAnnotationsPresent(deploymentUnit)) {
      WeldLogger.DEPLOYMENT_LOGGER.cdiAnnotationsButNoBeansXML(deploymentUnit);
    return;
  final ServiceName weldServiceName=parent.getServiceName().append(WeldService.SERVICE_NAME);
  deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES,weldServiceName);
  final Set<ServiceName> jpaServices=new HashSet<ServiceName>();
  if (deploymentUnit.getParent() != null) {
    return;
  WeldLogger.DEPLOYMENT_LOGGER.startingServicesForCDIDeployment(phaseContext.getDeploymentUnit().getName());
  final Module module=deploymentUnit.getAttachment(Attachments.MODULE);
  final ModuleSpecification moduleSpecification=deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
  final Set<BeanDeploymentArchiveImpl> beanDeploymentArchives=new HashSet<BeanDeploymentArchiveImpl>();
  final Map<ModuleIdentifier,BeanDeploymentModule> bdmsByIdentifier=new HashMap<ModuleIdentifier,BeanDeploymentModule>();
  final Map<ModuleIdentifier,ModuleSpecification> moduleSpecByIdentifier=new HashMap<ModuleIdentifier,ModuleSpecification>();
  final BeanDeploymentModule rootBeanDeploymentModule=deploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
  final EEModuleDescription eeModuleDescription=deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
  bdmsByIdentifier.put(module.getIdentifier(),rootBeanDeploymentModule);
  moduleSpecByIdentifier.put(module.getIdentifier(),moduleSpecification);
  beanDeploymentArchives.addAll(rootBeanDeploymentModule.getBeanDeploymentArchives());
  final Set<ClassLoader> subDeploymentLoaders=new HashSet<ClassLoader>();
  getJpaDependencies(deploymentUnit,jpaServices);
    getJpaDependencies(deploymentUnit,jpaServices);
    if (subDeploymentModule == null) {
      continue;
    subDeploymentLoaders.add(subDeploymentModule.getClassLoader());
    final BeanDeploymentModule bdm=subDeployment.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
    if (bdm == null) {
      continue;
    beanDeploymentArchives.addAll(bdm.getBeanDeploymentArchives());
    bdmsByIdentifier.put(subDeploymentModule.getIdentifier(),bdm);
    moduleSpecByIdentifier.put(subDeploymentModule.getIdentifier(),subDeploymentModuleSpec);
    bdm.addService(EjbInjectionServices.class,ejbInjectionServices);
  for (  Map.Entry<ModuleIdentifier,BeanDeploymentModule> entry : bdmsByIdentifier.entrySet()) {
    final ModuleSpecification bdmSpec=moduleSpecByIdentifier.get(entry.getKey());
    final BeanDeploymentModule bdm=entry.getValue();
    if (bdm == rootBeanDeploymentModule) {
      continue;
    for (    ModuleDependency dependency : bdmSpec.getSystemDependencies()) {
      BeanDeploymentModule other=bdmsByIdentifier.get(dependency.getIdentifier());
      if (other != null && other != bdm) {
        bdm.addBeanDeploymentModule(other);
  final WeldDeployment deployment=new WeldDeployment(beanDeploymentArchives,extensions,module,subDeploymentLoaders);
  final WeldContainer weldContainer=new WeldContainer(deployment,Environments.EE_INJECT);
  final ValidatorFactory factory=deploymentUnit.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY);
  weldContainer.addWeldService(ValidationServices.class,new WeldValidationServices(factory));
  weldContainer.addWeldService(EjbInjectionServices.class,ejbInjectionServices);
  rootBeanDeploymentModule.addService(EjbInjectionServices.class,ejbInjectionServices);
  weldContainer.addWeldService(EjbServices.class,new WeldEjbServices(deploymentUnit.getServiceRegistry()));
  weldContainer.addWeldService(JpaInjectionServices.class,rootJpaInjectionServices);
  final WeldService weldService=new WeldService(weldContainer,deploymentUnit.getName());
  final ServiceBuilder<WeldContainer> weldServiceBuilder=serviceTarget.addService(weldServiceName,weldService);
  weldServiceBuilder.addDependencies(TCCLSingletonService.SERVICE_NAME);
  installResourceInjectionService(serviceTarget,deploymentUnit,weldService,weldServiceBuilder);
  installSecurityService(serviceTarget,deploymentUnit,weldService,weldServiceBuilder);
  installTransactionService(serviceTarget,deploymentUnit,weldService,weldServiceBuilder);
  weldServiceBuilder.addDependencies(jpaServices);
  weldServiceBuilder.addDependency(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
  weldServiceBuilder.install();
}
getJpaDependencies{
  for (  ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) {
    final PersistenceUnitMetadataHolder persistenceUnits=root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
    if (persistenceUnits != null && persistenceUnits.getPersistenceUnits() != null) {
      for (      final PersistenceUnitMetadata pu : persistenceUnits.getPersistenceUnits()) {
        final Properties properties=pu.getProperties();
        final String jpaContainerManaged=properties.getProperty(Configuration.JPA_CONTAINER_MANAGED);
        final boolean deployPU=(jpaContainerManaged == null || Boolean.parseBoolean(jpaContainerManaged));
        if (deployPU) {
          final ServiceName serviceName=PersistenceUnitServiceImpl.getPUServiceName(pu);
          jpaServices.add(serviceName);
}
installSecurityService{
  final WeldSecurityServices service=new WeldSecurityServices();
  final ServiceName serviceName=deploymentUnit.getServiceName().append(WeldSecurityServices.SERVICE_NAME);
  serviceTarget.addService(serviceName,service).addDependency(ServiceBuilder.DependencyType.OPTIONAL,SimpleSecurityManagerService.SERVICE_NAME,SimpleSecurityManager.class,service.getSecurityManagerValue()).install();
  weldServiceBuilder.addDependency(serviceName,WeldSecurityServices.class,weldService.getSecurityServices());
}
installResourceInjectionService{
  final WeldResourceInjectionServices service=new WeldResourceInjectionServices();
  final ServiceName serviceName=deploymentUnit.getServiceName().append(WeldResourceInjectionServices.SERVICE_NAME);
  serviceTarget.addService(serviceName,service).install();
  weldServiceBuilder.addDependency(serviceName,WeldResourceInjectionServices.class,weldService.getResourceInjectionServices());
}
installTransactionService{
  final WeldTransactionServices weldTransactionServices=new WeldTransactionServices();
  final ServiceName weldTransactionServiceName=deploymentUnit.getServiceName().append(WeldTransactionServices.SERVICE_NAME);
  serviceTarget.addService(weldTransactionServiceName,weldTransactionServices).addDependency(TransactionManagerService.SERVICE_NAME,TransactionManager.class,weldTransactionServices.getInjectedTransactionManager()).addDependency(UserTransactionService.SERVICE_NAME,UserTransaction.class,weldTransactionServices.getInjectedTransaction()).install();
  weldServiceBuilder.addDependency(weldTransactionServiceName,WeldTransactionServices.class,weldService.getWeldTransactionServices());
}
undeploy{
  final ServiceName weldTransactionServiceName=context.getServiceName().append(WeldTransactionServices.SERVICE_NAME);
  final ServiceController<?> serviceController=context.getServiceRegistry().getService(weldTransactionServiceName);
  if (serviceController != null) {
    serviceController.setMode(ServiceController.Mode.REMOVE);
}
